//
//  YCTableView.m
//  KuaiYi
//
//  Created by 刘胤辰 on 16/7/5.
//  Copyright © 2016年 it.com. All rights reserved.
//

#import "YCTableView.h"
#import "YCCaseManagerVC.h"
#import "YCShareFriendVC.h"
#import "YCAboutProductVC.h"
#import "YCAttentionDoctorVC.h"
#import "YCDoctorApplyVC.h"
#import "YCSetUpAndHelpVC.h"
#import "YCLeftViewVC.h"

@interface YCTableView()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong)NSMutableArray *arrData;

@end

@implementation YCTableView

-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    
    self=[super initWithFrame:frame style:style];
    
    [self registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    self.delegate=self;
    self.dataSource=self;
    
    self.tableHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 0.001)];
    
    //数据源
    NSArray *array1 = @[@"名医通申请",@"病例管理",@"关注医生"];
    NSArray *array2 = @[@"设置与帮助",@"关于产品",@"分享给好友"];
    
    self.arrData=[NSMutableArray array];
    
    [self.arrData addObject:array1];
    [self.arrData addObject:array2];
    
    return self;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.arrData.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cellID"];
    if (cell==nil) {
        
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"];
    }
//    UIImageView *jianTou=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow_right_black"]];
//    jianTou.frame=CGRectMake(200, 0, 20, 20);
    //[cell.contentView addSubview:jianTou];
    
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    
    
    NSArray *array=self.arrData[indexPath.section];
    
    cell.textLabel.text=array[indexPath.item];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UIViewController *vc;
    
    if (indexPath.section==0) {
        
        switch (indexPath.item) {
            case 0:
                
                vc=[[YCDoctorApplyVC alloc]init];
            case 1:
                
                vc=[[YCCaseManagerVC alloc]init];
                
            default:
                vc=[[YCAttentionDoctorVC alloc]init];
                break;
        }
    }else{
        
        switch (indexPath.item) {
            case 0:
                
                vc=[[YCSetUpAndHelpVC alloc]init];
            case 1:
                
                vc=[[YCAboutProductVC alloc]init];
                
            default:
                vc=[[YCShareFriendVC alloc]init];
                break;
        }
    }
    
    //获取当前view的控制器
    YCLeftViewVC *leftVC=[self loadVC];
    
    NSArray *array=self.arrData[indexPath.section];
    
    vc.title=array[indexPath.item];
    
//    UIBarButtonItem *leftBtn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"JianTou-1"] style:UIBarButtonItemStyleDone target:self action:@selector(popVC)];
    
    
    
    
    //vc.modalTransitionStyle=UIModalTransitionStylePartialCurl;
    
    [leftVC jumpToOtherViewController:vc];
    
    //[tableView deselectRowAtIndexPath:indexPath animated:YES];

    
}

-(void)popVC{
    
    
}

-(YCLeftViewVC *)loadVC{
    
    for (UIView *next=[self superview]; next; next=next.superview) {
        
        UIResponder *nextResponder=[next nextResponder];
        if ([nextResponder isKindOfClass:[YCLeftViewVC class]]) {
            
            return(YCLeftViewVC *)nextResponder;
        }
    }
    return nil;
}

-(void)layoutSubviews{
    
    [super layoutSubviews];
}

@end
